﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Database;
using Business;

namespace DT5_Anh09110006_Hung09110044_Vu09110157.QuanLy
{
    public partial class SuaHocVienLopHoc : System.Web.UI.Page
    {
        Business.QuanLyHocVien_LopHoc qlhocvien_lophoc = new Business.QuanLyHocVien_LopHoc();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["MaHocVien"] != null && Session["MaLopHoc"]!=null)
                {
                    loaddulieu();
                }
                else
                {
                    Response.Redirect("ChiTietLopHoc.aspx");
                }
            }

        }
        public void loaddulieu()
        {
            HocVien_LopHoc hocvien_lophoc = qlhocvien_lophoc.LayHocVienLopHoc(Session["MaLopHoc"].ToString(),
                                                            Session["MaHocVien"].ToString());
            lblMaLop.Text = hocvien_lophoc.MaLop;
            lblMaHV.Text = hocvien_lophoc.MaHV;
            txtDiem1.Text = hocvien_lophoc.Diem1.ToString();
            txtDiem2.Text = hocvien_lophoc.Diem2.ToString();
            ddlHocPhi.SelectedValue = hocvien_lophoc.DongHocPhi.ToString();

        }
        protected void btnCapNhatLopHoc_Click(object sender, EventArgs e)
        {
            Session["MaHocVien"] = null;
            HocVien_LopHoc hocvien_lophoc = new HocVien_LopHoc
            {
                MaLop = lblMaLop.Text,
                MaHV = lblMaHV.Text,
                Diem1 = int.Parse(txtDiem1.Text),
                Diem2 = int.Parse(txtDiem2.Text),
                DongHocPhi = bool.Parse(ddlHocPhi.SelectedValue)
            };

            if (qlhocvien_lophoc.CapNhatHocVienLopHoc(hocvien_lophoc))
            {
                Response.Write("<script language='javascript' type='text/javascript'>"
                               + " alert('Chỉnh sửa thành công');"
                               + "window.location='ChiTietLopHoc.aspx'"
                               + "</script>");

            }
            else
            {
                Response.Write("<script language='javascript' type='text/javascript'>"
                            + "alert('Không thể chỉnh sửa học viên này');"
                            + "window.location='ChiTietLopHoc.aspx'"
                            + "</script>");

            }
        }

        protected void btnQuayLai_Click(object sender, EventArgs e)
        {
            Session["MaHocVien"] = null;
            Response.Redirect("ChiTietLopHoc.aspx");
        }
    }
}